home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / applic / ntp / acts.arc / WRTBUF.C < prev   
Encoding:
C/C++ Source or Header  |  1988-10-14  |  2.0 KB  |  90 lines

  1. void wrtbuf(obuf)
  2. char obuf[];
  3. {
  4. /*
  5.         this subroutine writes the characters in obuf to
  6.         a com port. if BIOS is defined, then the operation
  7.         is done via calls to the BIOS routines.  if BIOS is
  8.         not defined, then the operation is performed using
  9.         direct input output operations on the port whose hardware
  10.         address is defined by global cmadr.
  11.         cmadr was initialized by the subroutine inilin based on the
  12.         user input parameter cmport.
  13.         
  14.         in either case:
  15.         the operation continues until a 0 byte is found in the input buffer
  16.         and the port should have been initialized by somebody else.
  17. */
  18. #include "nbstime.h"
  19. #include <stdio.h>
  20. #ifdef IBMPC
  21. #include <dos.h>
  22. #endif
  23. int j;
  24. #ifdef IBMPC
  25. unsigned char stat;
  26. char cc;
  27. #ifdef BIOS
  28. extern int cmport;
  29. #endif
  30. #ifndef BIOS
  31. extern int cmadr;
  32. #endif
  33. #endif
  34. #ifdef SUN
  35. extern int cmport;
  36. #endif
  37. int t;
  38. #ifdef IBMPC
  39. int tlimit= -20000;
  40. #endif
  41. extern int debug;
  42. #ifdef SUN
  43.     for(j=0; obuf[j] != 0; j++) ;   /* find number of bytes */
  44.     t=write(cmport,&obuf[0],j);
  45.     if(t < 1)
  46.        {
  47.        printf("\n write failed, %d chars. written",t);
  48.        abort();
  49.        }
  50.     return;
  51. #endif
  52. #ifdef IBMPC
  53.         t=tlimit;
  54.         for(j=0; (cc=obuf[j]) != 0; j++)
  55.         {
  56. /*
  57.         check status and wait until ready
  58. */
  59.         do
  60.            {
  61.            #ifdef BIOS
  62.            _AH=3;
  63.            _DX=cmport;
  64.            geninterrupt(0x14);
  65.            stat=_AH;
  66.        #endif
  67.        #ifndef BIOS
  68.            stat=inportb(cmadr+5);
  69.            #endif
  70.            t++;
  71.            if(t == 0)
  72.               {
  73.               printf("\n Write failed. Modem not ready.");
  74.               return;
  75.               }
  76.            }   while( (stat & 0x20) == 0 );
  77.         #ifdef BIOS
  78.         _AL=cc;
  79.         _AH=1;
  80.         _DX=cmport;
  81.         geninterrupt(0x14);
  82.     #endif
  83.     #ifndef BIOS
  84.         outportb(cmadr,cc);
  85.         #endif
  86.         t=tlimit;
  87.         }
  88. #endif
  89. }
  90.